import Vue from 'vue'
import axios from 'axios'

axios.interceptors.request.use(function(request){
    //获取token
    var tokenString = localStorage.getItem("login_data")||'{}' //获取的字符串格式的用户信息
    var token = JSON.parse(tokenString).token //使用json进行格式转化 string --> object
    if(token){
        request.headers.Authorization = token
    }
    return request
})

axios.interceptors.response.use(function(response){
    return response.data
})


Vue.prototype.$http = axios
export default axios